﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace DataService
{
    public class Service1 : IService1
    {
        public int GetTemperature()
        {
            var value = 0;

            using(var con = new SqlConnection("Server=tcp:emikuqiw7t.database.windows.net,1433;Database=GrillMaster;User ID=grillmasteruser@emikuqiw7t;password=GrillMaster!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection = con;
                    con.Open();
                    cmd.CommandText = "select temperature from Temperatures where ID=1";
                    
                    using(var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            value = Convert.ToInt16(reader[0]);
                        }
                    }
                }
            }

            return value;
        }
    }
}
